package bounds.upper

object ViewBounds {
  def main(args: Array[String]): Unit = {

    val unit = new CompareComm(20, 30)
    println(unit.greater)
    //视图定界
    val tom = new Person2("tom", 23)
    val jack = new Person2("jack", 34)
    //调用自己写的隐式函数
    import bounds.MyImplict._
    val compareComm2 = new CompareComm2(tom, jack)
    println(compareComm2.geatter2)

  }

}

class CompareComm[T <% Comparable[T]](o1: T, o2: T) {
  def greater = if (o1.compareTo(o2) > 0) o1 else o2
}

class Person2(val name: String, val age: Int) {

  override def toString = s"Person2(name=$name, age=$age)"
}

class CompareComm2[T <% Ordered[T]](ob1: T, ob2: T) {
  def getter = if (ob1 > ob2) ob1 else ob2

  def geatter2 = if (ob1.compareTo(ob2) > 0) ob1 else ob2
}